<?php

// ##############################################################################||
// #                                                                 
// #   MySmartBB Version 1.7.0	                                      
// #   http://www.MySmartBB.com                                      
// #   Copyright (c) 2008 by MySmartBB team                           
// #   license http://opensource.org/licenses/gpl-license.php GNU Public License
// #                                                             
// #   filename : topic_cp.php
// #   subject and reply control panel for moderators and admins         
// #                                                                  
// ##############################################################################||

// ** General definitions **

     define('NOT_IN_INDEX',0);
     include('common.php');
     $temp = md5(time());
     $Smarty->assign('temp',$temp);

     $mod_per = 0;
     $_REQUEST['D1'] = $SF->SafeSQL($_REQUEST['D1']);
     $_REQUEST['D2'] = $SF->SafeSQL($_REQUEST['D2']);

     if ($_GET['cp'] == 1)
     {
         $id  = intval($_GET['id']);
         $sid = intval($_GET['sid']);


         $subject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='$id'");
         $subject_num   = $DB->sql_num_rows($subject_query);
         $subject_row   = $DB->sql_fetch_array($subject_query);

         if ($groupper_row['group_mod'] == 1)
         {
             $getsectionmod_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "sectionadmin WHERE section_id='" . $subject_row['section'] . "' AND member_id='" . $member_row['id']  . "'");
             $getsectionmod_num   = $DB->sql_num_rows($getsectionmod_query);

             if ($getsectionmod_num != 0)
             {
                 $mod_per = 1;
             }
         }

         if ($groupper_row['admincp_allow'] == 1 or $groupper_row['vice'] == 1)
         {
             $mod_per = 1;
         }

         if ($mod_per == 1)
         {

             if ($_REQUEST['D1'] == 1)
             {
                 $SF->html_title_page('حذف موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['del_subject'] == 1)
                 {
                     $Smarty->assign('id',$id);
                     $Smarty->display('post_delete-subject.tpl');
                 }
             }
             elseif ($_REQUEST['D1'] == 2)
             { 
			     $SF->html_title_page('تحرير مشاركة - (Powered By MySmartBB Universal)');
                 include('includes/SmartCode.js');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['edit_subject'] == 1)
                 {
                     $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");

                     $smiles_row = array();
                     while ($smile_row = $DB->sql_fetch_array($smiles_query))
                     {
                         $smiles_row[] = $smile_row;
                         $Smarty->assign('smiles_row',$smiles_row);
                     }

                     $icons_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type<>'0' ORDER BY id DESC");
                     $icons_row = array();
                     while ($icon_row = $DB->sql_fetch_array($icons_query))
                     {
                         $icons_row[] = $icon_row;
                         $Smarty->assign('icons_row',$icons_row);
                     }

                     $section_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$subject_row['section']."'");
                     $section_row   = $DB->sql_fetch_array($section_query);

                     if ($section_row['sub_section'] == 1)
                     {
                         $getmainsection_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$section_row['from_sub_section']."'");
                         $getmainsection_row = $DB->sql_fetch_array($getmainsection_query);
                         $Smarty->assign('path_bar',"<a href=forum.php?show=1&id=".$getmainsection_row['id'].">".$SF->SafeOutPuts($getmainsection_row['title'])."</a> -> <a href=forum.php?show=1&id=".$section_row['id'].">".$SF->SafeOutPuts($section_row['title'])."</a> -> <a href=show.php?main=1&id=".$subject_row['id'].">".$SF->SafeOutPuts($subject_row['title'])."</a> -> تحرير الموضوع");
                     }
                     else
                     {
                         $Smarty->assign('path_bar',"<a href=forum.php?show=1&id=".$section_row['id'].">".$SF->SafeOutPuts($section_row['title'])."</a> -> <a href=show.php?main=1&id=".$subject_row['id'].">".$SF->SafeOutPuts($subject_row['title'])."</a> -> تحرير الموضوع");
                     }

                     $SF->GetSmartCode();
                     $Smarty->display('path-bar.tpl');
                     $Smarty->assign_by_ref('subject_row',$subject_row);
                     $Smarty->display('post_edit-subject_for-admin.tpl');
                 }
             }
             elseif ($_REQUEST['D1'] == 3)
             {
					$SF->html_title_page('تثبيت موضوع - (Powered By MySmartBB Universal)');
                  if ($groupper_row['admincp_allow'] == 1 or $groupper_row['stick_subject'] == 1)
                  {
                      $update = $DB->sql_query("UPDATE " . $db_prefix . "subject SET stick='1' WHERE id='$id'");
                      if ($update)
                      {
                          if ($info_row['supermember_logs'] == 1)
                          {
                              $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','تثبيت الموضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                          }

							$Smarty->assign('msgg','ثُبِّتَ الموضوع  بنجاح'); 
							$Smarty->assign('GO','show.php?main=1&id=' . $id);
							$SF->go_to('show.php?main=1&id=' . $id,2);            
							$Smarty->display('loading.tpl');
                       
                      }
                  }
             }
             elseif ($_REQUEST['D1'] == 4)
             {
				$SF->html_title_page('الغاء تثبيت موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['unstick_subject'] == 1)
                 {
                     $update = $DB->sql_query("UPDATE " . $db_prefix . "subject SET stick='0' WHERE id='$id'");
                     if ($update)
                     {
                         if ($info_row['supermember_logs'] == 1)
                         {
                             $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','إلغاء تثبيت الموضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                         }

							$Smarty->assign('msgg','أُلغيَ تثبيت الموضوع بنجاح'); 
							$Smarty->assign('GO','show.php?main=1&id=' . $id);
							$SF->go_to('show.php?main=1&id=' . $id,2);            
							$Smarty->display('loading.tpl');
                     }
                 }
             }
             elseif ($_REQUEST['D1'] == 5)
             {
                 $SF->html_title_page('نقل موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['move_subject'] == 1)
                 {
                     $getcursection_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE main_section<>'1' AND linksection<>'1' AND id<>'" . $subject_row['section'] . "' ORDER BY sort ASC");
                     $getsection_query    = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE main_section<>'1' AND id='" . $subject_row['section'] . "' ORDER BY sort ASC");
                     $getsection_row      = $DB->sql_fetch_array($getsection_query);

                     $getcursection_rows = array();
                     while ($getcursection_row = $DB->sql_fetch_array($getcursection_query))
                     {
                         $getcursection_rows[] = $getcursection_row;
                         $Smarty->assign('getcursection_rows',$getcursection_rows);
                     }

                     $Smarty->assign('s_id',$id);
                     $Smarty->assign_by_ref('getsection_row',$getsection_row);
                     $Smarty->display('post_move-subject.tpl');
                 }
             }
             elseif ($_REQUEST['D1'] == 6)
             {
				$SF->html_title_page('اغلاق موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['close_subject'] == 1)
                 {
                     $update = $DB->sql_query("UPDATE " . $db_prefix . "subject SET close='1' WHERE id='$id'");
                     if ($update)
                     {
                         if ($info_row['supermember_logs'] == 1)
                         {
                             $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','إغلاق موضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                         }

					$Smarty->assign('msgg','أُغلِقَ الموضوع'); 
					$Smarty->assign('GO','show.php?main=1&id=' . $id);
					$SF->go_to('show.php?main=1&id=' . $id,2);            
					$Smarty->display('loading.tpl');

                     }
                 }
             }
             elseif ($_REQUEST['D1'] == 7)
             {
				 $SF->html_title_page('فتح موضوع - (Powered By MySmartBB Universal)');
                 $update = $DB->sql_query("UPDATE " . $db_prefix . "subject SET close='0' WHERE id='$id'");
                 if ($update)
                 {
                     if ($info_row['supermember_logs'] == 1)
                     {
                         $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','فتح موضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                     }

					$Smarty->assign('msgg','فُتِحَ الموضوع'); 
					$Smarty->assign('GO','show.php?main=1&id=' . $id);
					$SF->go_to('show.php?main=1&id=' . $id,2);            
					$Smarty->display('loading.tpl');

                 }
             }
             elseif ($_REQUEST['D2'] == 1)
             {
				$SF->html_title_page('حذف رد - (Powered By MySmartBB Universal)');
                 $id = intval($_GET['id']);

                 $writer_query   = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE id='$sid'");
                 $writer_row     = $DB->sql_fetch_array($writer_query);

                 $user_query     = $DB->sql_query("SELECT * FROM " . $db_prefix . "member WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
                 $user_row       = $DB->sql_fetch_array($user_query);

                 $update         = $DB->sql_query("UPDATE " . $db_prefix . "reply SET delete_topic='1' WHERE id='$sid'");
                 $reply_num      = $DB->sql_num_rows($DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE delete_topic<>'1' AND subject_id='" . $writer_row['subject_id'] . "'"));
                 $update_subject = $DB->sql_query("UPDATE " . $db_prefix . "subject SET reply_number='" . $reply_num . "' WHERE id='" . intval($_GET['id']) . "'");

                 if ($user_row['posts'] > 0)
                 {
                     $update_member  = $DB->sql_query("UPDATE " . $db_prefix . "member SET posts=posts-1 WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
                 }

                 $sectionlast_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $writer_row['section'] . "' AND last_subjectid='" . $writer_row['subject_id'] . "'");
                 $sectionlast_num   = $DB->sql_num_rows($sectionlast_query);
                 $sectionlast_row   = $DB->sql_fetch_array($sectionlast_query);

                 if ($sectionlast_num > 0)
                 {
                     $getlastsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE section='" . $writer_row['section'] . "' AND delete_topic<>'1' ORDER BY write_time DESC LIMIT 1,1");
                     $getlastsubject_row   = $DB->sql_fetch_array($getlastsubject_query);

                     if ($getlastsubject_row['reply_number'] > 0)
                     {
                         $getlastreply_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id='" . $getlastsubject_row['id'] . "' ORDER BY id DESC LIMIT 1,1");
                         $getlastreply_row   = $DB->sql_fetch_array($getlastreply_query);
                         $lastwriter         = $SF->SafeSQL($getlastreply_row['writer']);
                     }
                     else
                     {
                         $lastwriter = $SF->SafeSQL($getlastsubject_row['writer']);
                     }

                     $update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='" . $lastwriter . "',last_subject='" . $SF->SafeSQL($getlastsubject_row['title']) . "',last_subjectid='" . $getlastsubject_row['id'] . "',last_date='" . $date . "' WHERE id='" . $getlastsubject_row['section'] . "'");
                 }

                 if ($update)
                 {
                     if ($info_row['supermember_logs'] == 1)
                     {
                         $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','حذف رد','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                     }
				$Smarty->assign('msgg','حُذِف الرد بنجاح'); 
                $Smarty->assign('GO','show.php?main=1&id=' . $id);
				$SF->go_to('show.php?main=1&id=' . $id,2);        
                $Smarty->display('loading.tpl');

                 }
             }
             elseif ($_REQUEST['D2'] == 2)
             {
				$SF->html_title_page('تحرير رد - (Powered By MySmartBB Universal)');
                 include('includes/SmartCode.js');


                 $subject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE id='$sid'");
                 $subject_row   = $DB->sql_fetch_array($subject_query);

                 $smiles_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type='0' ORDER BY id ASC LIMIT 0,13");
                 $smiles_row = array();
                 while ($smile_row = $DB->sql_fetch_array($smiles_query))
                 {
                     $smiles_row[] = $smile_row;
                     $Smarty->assign('smiles_row',$smiles_row);
                 }

                 $icons_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "smiles WHERE smile_type<>'0' ORDER BY id DESC");
                 $icons_row = array();
                 while ($icon_row = $DB->sql_fetch_array($icons_query))
                 {
                     $icons_row[] = $icon_row;
                     $Smarty->assign('icons_row',$icons_row);
                 }

                 $section_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$subject_row['section']."'");
                 $section_row   = $DB->sql_fetch_array($section_query);

                 $getsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id = '".$subject_row['subject_id']."'");
                 $getsubject_row   = $DB->sql_fetch_array($getsubject_query);

                 if ($section_row['sub_section'] == 1)
                 {
                     $getmainsection_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id = '".$section_row['from_sub_section']."'");
                     $getmainsection_row = $DB->sql_fetch_array($getmainsection_query);
                     $Smarty->assign('path_bar','<a href=forum.php?show=1&id='.$SF->SafeOutPuts($getmainsection_row['title']).'>'.$getmainsection_row['title'].'</a> -> <a href=forum.php?show=1&id='.$section_row['id'].'>'.$SF->SafeOutPuts($section_row['title']).'</a> -> <a href=show.php?main=1&id='.$getsubject_row['id'].'>'.$SF->SafeOutPuts($getsubject_row['title']).'</a> -> تحرير رد');
                 }
                 else
                 {
                     $Smarty->assign('path_bar','<a href=forum.php?show=1&id='.$section_row['id'].'>'.$SF->SafeOutPuts($section_row['title']).'</a> -> <a href=show.php?main=1&id='.$getsubject_row['id'].'>'.$SF->SafeOutPuts($getsubject_row['title']).'</a> -> تحرير رد');
                 }

                 $SF->GetSmartCode();
                 $Smarty->display('path-bar.tpl');
                 $Smarty->assign('id',$id);
                 $Smarty->assign('sid',$sid);
                 $Smarty->assign_by_ref('subject_row',$subject_row);
                 $Smarty->display('post_edit-reply_for-admin.tpl');
             }

             if ($_GET['update_subject'] == 1)
             {
				 $SF->html_title_page('تحرير موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['edit_subject'] == 1)
                 {
                     if (empty($_POST['T1']) or empty($_POST['S1']))
                     {
                         $SF->error('يرجى تعبئة كافة المعلومات');
                     }

                     $text   = $SF->SafeSql($SF->SafeOutPuts($_POST['S1']));
					 	 
					 $update = $DB->sql_query("UPDATE " . $db_prefix . "subject SET title='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T1'])) . "',text='" . $text . "',icon='" . $SF->SafeSql($SF->SafeOutPuts($_POST['R1'])) . "',subject_describe='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T2'])) . "',action_by='" . $SF->SafeSQL($member_row['username']) . "',subscribe='" . $SF->SafeSql($SF->SafeOutPuts($_POST['subs'])) . "',edit_reason='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T9'])) . "' WHERE id='" . intval($_GET['id']) . "'");

                     $writer_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . intval($_GET['id']) . "'");
                     $writer_row   = $DB->sql_fetch_array($writer_query);

                     $sectionlast_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $writer_row['section'] . "' AND last_subjectid='" . $writer_row['id'] . "'");
                     $sectionlast_num   = $DB->sql_num_rows($sectionlast_query);
                     $sectionlast_row   = $DB->sql_fetch_array($sectionlast_query);

                     if ($sectionlast_num > 0)
                     {
                         $update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_subject='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T1'])) . "' WHERE id='" . $sectionlast_row['id'] . "'");
                     }

                     if ($update)
                     {
                         if ($info_row['supermember_logs'] == 1)
                         {
                             $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','تحرير موضوع','" . $SF->SafeSql($SF->SafeOutPuts($subject_row['title'])) . "','" . $subject_row['id'] . "','" . $date . "')");
                         }

						$Smarty->assign('msgg','حُـرِّرَ الموضوع بنجاح'); 
						$Smarty->assign('GO','show.php?main=1&id=' . $id);
						$SF->go_to('show.php?main=1&id=' . $id,2);        
						$Smarty->display('loading.tpl');

                     }
                 }
             }

			if ($_GET['update_move'] == 1)
             {
				$SF->html_title_page('نقل موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['move_subject'] == 1)
                 {
                     $writer_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='" . intval($_GET['id']) . "'");
                     $writer_row   = $DB->sql_fetch_array($writer_query);

                     $sectionlast_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $writer_row['section'] . "' AND last_subjectid='" . $writer_row['id'] . "'");
                     $sectionlast_num   = $DB->sql_num_rows($sectionlast_query);
                     $sectionlast_row   = $DB->sql_fetch_array($sectionlast_query);

                     if ($sectionlast_num > 0)
                     {
                         $getlastsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE section='" . $writer_row['section'] . "' AND delete_topic<>'1' AND id<>'" . $writer_row['id'] . "' ORDER BY write_time DESC LIMIT 0,1");
                         $getlastsubject_row   = $DB->sql_fetch_array($getlastsubject_query);
                         $getlastsubject_num   = $DB->sql_num_rows($getlastsubject_query);

                         if ($getlastsubject_num != 0)
                         {
                             if ($getlastsubject_row['reply_number'] > 0)
                             {
                                 $getlastreply_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id='" . $getlastsubject_row['id'] . "' ORDER BY id DESC LIMIT 1,1");
                                 $getlastreply_row   = $DB->sql_fetch_array($getlastreply_query);
                                 $lastwriter         = $SF->SafeSQL($getlastreply_row['writer']);
                             }
                             else
                             {
                                 $lastwriter = $SF->SafeSQL($getlastsubject_row['writer']);
                             }

                             $update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='" . $lastwriter . "',last_subject='" . $SF->SafeSQL($getlastsubject_row['title']) . "',last_subjectid='" . $getlastsubject_row['id'] . "',last_date='" . $date . "' WHERE id='" . $sectionlast_row['id'] . "'");
                         }
						 else{
							$update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='',last_subject='',last_subjectid='',last_date='' WHERE id='" . $sectionlast_row['id'] . "'");
						}
                     }
					 
						
					 //--//
					 $old_section_query = $DB->sql_query("SELECT * FROM `".$db_prefix."section` WHERE `id`='".$writer_row['section']."'");
					 $old_section = $DB->sql_fetch_array($old_section_query);
					 $is_sec1 = $old_section['sec_section'];
					 $new_section_query = $DB->sql_query("SELECT * FROM `".$db_prefix."section` WHERE id='".intval($_POST['s_D1'])."'");
					 $new_section = $DB->sql_fetch_array($new_section_query);
					 
					 $is_sec2 = $old_section['sec_section'];
					 
					 if ( $is_sec2 == 0 )
					 {
					 	$osms_query = $DB->sql_query("SELECT * FROM `".$db_prefix."section` WHERE id='".$new_section['from_main_section']."'");
						$osms_row = $DB->sql_fetch_array($osms_query);
						if ( $osms_row['sec_section'] == 1 )
						{
							$is_sec2 = 1;
						}
					}					 
					 
					 $subjupd = "";
					 
					 if ( $is_sec1 == 0 and $is_sec2 == 1 )
					 {
					 	$subjupd = " , `sec_subject`='1' ";
					 }
					 elseif ( $is_sec1 == 1 and $is_sec2 == 0 )
					 {
					 	$subjupd = " , `sec_subject`='0' ";
					 }	
					
					 

                     $update  = $DB->sql_query("UPDATE " . $db_prefix . "subject SET section='" . intval($_POST['s_D1']) . "'".$subjupd." WHERE id='" . intval($_GET['id']) ."'");
                     $update2 = $DB->sql_query("UPDATE " . $db_prefix . "reply SET section='" . intval($_POST['s_D1']) . "' WHERE subject_id='" . intval($_GET['id']) . "'");

                     if ($update)
                     {
					                      	
                     	// Tell Writer
                     	if ($_POST["D3"] == 1)
						{
							
							$sectionnew_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $_POST['s_D1'] ."'");
							$sectionnew_num   = $DB->sql_num_rows($sectionnew_query);
							$sectionnew_row   = $DB->sql_fetch_array($sectionnew_query);
							
							if ($sectionnew_num > 0)
							{
								$text = 'السلام عليكم و رحمة الله و بركاته ، هذه رسالة تُرسَل تلقائياً عند نقل أحد مواضيعك
								         
										 تم نقل الموضوع : [URL=http://'.$info_row["contactus_link"] .'/show.php?main=1&id='. $writer_row["id"] .'][color=blue]' . $writer_row['title'] . '[/color][/URL]
										 
										 إلى : [URL=http://'.$info_row["contactus_link"] .'/forum.php?show=1&id='. $sectionnew_row['id'] .'][color=blue]' . $sectionnew_row['title'] . '[/color][/URL]
										 
										 بواسطة : [URL=http://'.$info_row["contactus_link"] .'/misc.php?profile=1&id='. $member_row['id'] .'][color=blue]' . $member_row['username'].'[/color][/URL]';
										 
								if (!empty($_POST['T1']))
								{
									$text .= '
									
											السبب : [color=blue]' . $_POST['T1'] . '[/color]';
								}
								
								$pm_insert = $DB->sql_query("INSERT INTO " . $db_prefix . "pm(id,title,user_from,user_to,text,date,icon,folder) VALUES('NULL','نقل موضوعك','" . $SF->SafeSQL($member_row['username']) . "','" . $SF->SafeSQL($writer_row['writer']) . "','" . $text . "','" . $date . "','image/icons/i1.gif','inbox')");
								$update = $DB->sql_query("UPDATE " . $db_prefix . "member SET unread_pm=unread_pm+1 WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
							}
						} // end Tell Writer

						
                         if ($info_row['supermember_logs'] == 1)
                         {
                             $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','نقل موضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                         }
						 
                         $SF->UpdateSubForums();
						 $SF->UpdateForumsArray();
                         $SF->UpdateLastReplyArray();

						 
						$Smarty->assign('msgg','نُقِلَ الموضوع بنجاح'); 
						$Smarty->assign('GO','forum.php?show=1&id=' . $sid);
						$SF->go_to('forum.php?show=1&id=' . $sid,2);        
						$Smarty->display('loading.tpl');


                     }
                 }
             }
			 
             if ($_GET['update_reply'] == 1)
             {
				$SF->html_title_page('تحرير رد - (Powered By MySmartBB Universal)');
                 if (empty($_POST['S1']))
                 {
                     $SF->error('يرجى تعبئة كافة المعلومات');
                 }
				 
                 $text   = $SF->SafeSql($SF->SafeOutPuts($_POST['S1']));
				 
                 $update = $DB->sql_query("UPDATE " . $db_prefix . "reply SET title='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T1'])) . "',text='" . $text . "',icon='" . $SF->SafeSql($SF->SafeOutPuts($_POST['R1'])) . "',action_by='" . $SF->SafeSQL($member_row['username']) . "',actiondate=now(),subscribe='" . $SF->SafeSql($SF->SafeOutPuts($_POST['subs'])) . "',edit_reason='" . $SF->SafeSql($SF->SafeOutPuts($_POST['T9'])) . "' WHERE id='" . intval($_GET['sid']) . "'");

                 if ($update)
                 {
                     if ($info_row['supermember_logs'] == 1)
                     {
                         $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','تحرير رد','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                     }

					$Smarty->assign('msgg','حُـرِّرَ الرد بنجاح'); 
					$Smarty->assign('GO','show.php?main=1&id=' . $id);
					$SF->go_to('show.php?main=1&id=' . $id,2);       
					$Smarty->display('loading.tpl');

                 }
             }

             if ($_GET['delete_topic'] == 1)
             {
				$SF->html_title_page('حذف موضوع - (Powered By MySmartBB Universal)');
                 if ($groupper_row['admincp_allow'] == 1 or $groupper_row['del_subject'] == 1)
                 {
                     $id = intval($_GET['id']);

                     $writer_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE id='$id'");
                     $writer_row   = $DB->sql_fetch_array($writer_query);

                     $user_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "member WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
                     $user_row   = $DB->sql_fetch_array($user_query);

                     $update        = $DB->sql_query("UPDATE " . $db_prefix . "subject SET delete_topic='1',action_by='" . $SF->SafeSQL($member_row['username']) . "' WHERE id='$id'");
                     $update_reply  = $DB->sql_query("UPDATE " . $db_prefix . "reply SET delete_topic='1' WHERE subject_id='$id'");

                     if ($user_row['posts'] > 0)
                     {
                         $update_member  = $DB->sql_query("UPDATE " . $db_prefix . "member SET posts=posts-1 WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
                     }

                     if ($_POST['TE'] == 1)
                     {
                         $text = 'السلام عليكم و رحمة الله و بركاته ، هذه رسالة تُرسَل تلقائياً عند حذف أحد مواضيعك
                                  تم حذف الموضوع : [color=blue]' . $writer_row['title'] . '[/color]

                                  بواسطة : [color=blue]' . $member_row['username'].'[/color]';

                         if (!empty($_POST['Reason']))
                         {
                             $text .= '

                                       السبب : [color=blue]' . $_POST['Reason'] . '[/color]';
                         }

                         $pm_insert = $DB->sql_query("INSERT INTO " . $db_prefix . "pm(id,title,user_from,user_to,text,date,icon,folder) VALUES('NULL','حُذِفَ موضوعك','" . $SF->SafeSQL($member_row['username']) . "','" . $SF->SafeSQL($writer_row['writer']) . "','" . $text . "','" . $date . "','image/icons/i1.gif','inbox')");
                         $update = $DB->sql_query("UPDATE " . $db_prefix . "member SET unread_pm=unread_pm+1 WHERE username='" . $SF->SafeSQL($writer_row['writer']) . "'");
                     }

                     $sectionlast_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "section WHERE id='" . $writer_row['section'] . "' AND last_subjectid='" . $writer_row['id'] . "'");
                     $sectionlast_num   = $DB->sql_num_rows($sectionlast_query);
                     $sectionlast_row   = $DB->sql_fetch_array($sectionlast_query);

                     if ($sectionlast_num > 0)
                     {
                         $getlastsubject_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE section='" . $writer_row['section'] . "' AND delete_topic<>'1' AND id<>'" . $writer_row['id'] . "' ORDER BY write_time DESC LIMIT 0,1");
                         $getlastsubject_row   = $DB->sql_fetch_array($getlastsubject_query);
                         $getlastsubject_num   = $DB->sql_num_rows($getlastsubject_query);

                         if ($getlastsubject_num != 0)
                         {
                             if ($getlastsubject_row['reply_number'] > 0)
                             {
                                 $getlastreply_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id='" . $getlastsubject_row['id'] . "' AND delete_topic<>'1' ORDER BY id DESC LIMIT 0,1");
                                 $getlastreply_row   = $DB->sql_fetch_array($getlastreply_query);
                                 $lastwriter         = $SF->SafeSQL($getlastreply_row['writer']);
                             }
                             else
                             {
                                 $lastwriter = $SF->SafeSQL($getlastsubject_row['writer']);
                             }
							 							 
							if ($sectionlast_row['sub_section'] == 1)
							{
								$update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='" . $lastwriter . "',last_subject='" . $SF->SafeSQL($getlastsubject_row['title']) . "',last_subjectid='" . $getlastsubject_row['id'] . "',last_date='" . $SF->SafeSQL($getlastreply_row['write_date']) . "' WHERE id='" . $sectionlast_row['from_sub_section'] . "'");
							}
			 
                             $update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='" . $lastwriter . "',last_subject='" . $SF->SafeSQL($getlastsubject_row['title']) . "',last_subjectid='" . $getlastsubject_row['id'] . "',last_date='" . $SF->SafeSQL($getlastreply_row['write_date']) . "' WHERE id='" . $getlastsubject_row['section'] . "'");
                         }
                         else
                         {
							$update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='',last_subject='',last_subjectid='',last_date='' WHERE id='" . $writer_row['section'] . "'");
							 
							 if ($sectionlast_row['sub_section'] == 1)
							{	
									 	
							         $getlastsubjects_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "subject WHERE section='" . $sectionlast_row['from_sub_section'] . "' AND delete_topic<>'1' ORDER BY write_time DESC LIMIT 0,1");
									 $getlastsubjects_row   = $DB->sql_fetch_array($getlastsubjects_query);
									 $getlastsubjects_num   = $DB->sql_num_rows($getlastsubjects_query);
									
									if ($getlastsubjects_num != 0)
									{
										if ($getlastsubjects_row['reply_number'] > 0)
										{
											$getlastreply1_query = $DB->sql_query("SELECT * FROM " . $db_prefix . "reply WHERE subject_id='" . $getlastsubjects_row['id'] . "' AND delete_topic<>'1' ORDER BY id DESC LIMIT 0,1");
											$getlastreply1_row   = $DB->sql_fetch_array($getlastreply1_query);
											$lastwriter1         = $SF->SafeSQL($getlastreply1_row['writer']);
										}
										else
										{
											$lastwriter1 = $SF->SafeSQL($getlastsubjects_row['writer']);
										}
										
										$update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='" . $lastwriter1 . "',last_subject='" . $SF->SafeSQL($getlastsubjects_row['title']) . "',last_subjectid='" . $getlastsubjects_row['id'] . "',last_date='" . $date . "' WHERE id='" . $sectionlast_row['from_sub_section'] . "'");
							 
									}
									else
									{
									   $update_last = $DB->sql_query("UPDATE " . $db_prefix . "section SET last_writer='',last_subject='',last_subjectid='',last_date='' WHERE id='" . $sectionlast_row['from_sub_section'] . "'");
									}		
							}
							
                         }
                     }

                     if ($update)
                     {
                         if ($info_row['supermember_logs'] == 1)
                         {
                             $DB->sql_query("INSERT INTO " . $db_prefix . "supermemberlogs(id,username,edit_action,subject_title,subject_id,edit_date) VALUES('NULL','" . $SF->SafeSQL($member_row['username']) . "','حذف الموضوع','" . $SF->SafeSQL($subject_row['title']) . "','" . $subject_row['id'] . "','" . $date . "')");
                         }
							$SF->UpdateForumsArray();
							$SF->UpdateSubForums();
							$SF->UpdateLastReplyArray();

							$Smarty->assign('msgg','حُذِفَ الموضوع بنجاح'); 
							$Smarty->assign('GO','forum.php?show=1&id=' . $writer_row['section']);
							$SF->go_to('forum.php?show=1&id=' . $writer_row['section'],2);    
							$Smarty->display('loading.tpl');

                     }
                 }
             }
         }
     }

     $Smarty->display('footer.tpl');

?>